package locusts;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.AffineTransform;

public class ViewTranslateKeyListener implements KeyListener {

    AffineTransform viewTransform;

    public ViewTranslateKeyListener(AffineTransform viewTransform) {
        super();
        this.viewTransform = viewTransform;
    }

    public void keyTyped(KeyEvent arg0) {
    }

    public void keyPressed(KeyEvent arg0) {
//        System.out.println("KeyCode: " + arg0.getKeyCode());
        double translateAmount = 100;
        double scaleAmount = 0.9;
        switch (arg0.getKeyCode()) {
            case KeyEvent.VK_UP:
                viewTransform.translate(0, translateAmount);
                break;
            case KeyEvent.VK_DOWN:
                viewTransform.translate(0, -translateAmount);
                break;
            case KeyEvent.VK_LEFT:
                viewTransform.translate(translateAmount, 0);
                break;
            case KeyEvent.VK_RIGHT:
                viewTransform.translate(-translateAmount, 0);
                break;
            case KeyEvent.VK_MINUS:
            case KeyEvent.VK_UNDERSCORE:
                viewTransform.scale(scaleAmount, scaleAmount);
                break;
            case KeyEvent.VK_PLUS:
            case KeyEvent.VK_EQUALS:
                viewTransform.scale(1d / scaleAmount, 1d / scaleAmount);
                break;
            default:
        }
    }

    public void keyReleased(KeyEvent arg0) {
//        System.out.println("KeyCode: " + arg0.getKeyCode());
    }
}
